home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / mpss / keyscan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-20  |  1.2 KB  |  52 lines

  1.  
  2. /*******************************************************************************
  3. ********************************************************************************
  4. ********************************************************************************
  5.  
  6. PERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
  7. THIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
  8.  
  9.         P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
  10.  
  11.  
  12. ********************************************************************************
  13. ********************************************************************************
  14. *******************************************************************************/
  15. #include "header.h"
  16.  
  17. /*******************USEFUL ROUTINES FOR LOW LEVEL I/O**************************/
  18.  
  19. getbuf(cp,ptrnoofchars)
  20. register struct player *cp;
  21. long *ptrnoofchars;
  22. {
  23. if (*ptrnoofchars>0)
  24. {
  25. /* get buffer from terminal */
  26. read(cp->fd,cp->buf,*ptrnoofchars);
  27. cp->buftop=(int)(*ptrnoofchars);
  28. cp->bufptr=0;
  29. }
  30.  
  31. flushbuf(cp)
  32. register struct player *cp;
  33. {
  34. cp->buf[0]='\0';
  35. cp->buftop=0;
  36. cp->bufptr=0;
  37. }
  38.  
  39. getchr(cp)
  40. register struct player *cp;
  41. {
  42. if (cp->bufptr==cp->buftop) /*is buffer empty?*/
  43.     {    
  44.     flushbuf(cp); 
  45.     return('\0');
  46.     } else
  47.     return(cp->buf[cp->bufptr++]);
  48. }
  49.  
  50.  
  51.